package com.fantastic.service.zjs.impl;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.exception.sql.InsertException;
import com.fantastic.common.exception.sql.SelectException;
import com.fantastic.common.exception.sql.UpdateException;
import com.fantastic.common.utils.IsEmptyUtils;
import com.fantastic.mapper.zjs.CouponTypesMapper;
import com.fantastic.model.pojo.zjs.CouponTypes;
import com.fantastic.service.zjs.CouponTypesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/2 22:23
 * @description: 优惠券类型service接口实现类
 */
@Service
public class CouponTypesServiceImpl implements CouponTypesService {

    @Resource
    private CouponTypesMapper couponTypesMapper;

    /**
     * 查询优惠券类型信息
     *
     * @param couponTypes
     * @return
     */
    @Override
    public List<CouponTypes> listCouponTypes(CouponTypes couponTypes) {
        List<CouponTypes> couponTypesList = couponTypesMapper.listCouponTypes(couponTypes);
        IsEmptyUtils.listIsEmpty(new SelectException(RespStatusInfo.SELECT_NULL), couponTypesList);
        return couponTypesList;
    }

    /**
     * 查询单个优惠券类型信息
     *
     * @param couponTypeId
     * @return
     */
    @Override
    public CouponTypes getCouponTypes(Integer couponTypeId) {
        IsEmptyUtils.integerIsEmpty(new SelectException(RespStatusInfo.SELECT_NULL), couponTypeId);
        return couponTypesMapper.getCouponTypes(couponTypeId);
    }

    /**
     * 添加优惠券类型信息
     *
     * @param couponTypes
     * @return
     */
    @Override
    public Integer insertCouponTypes(CouponTypes couponTypes) {
        IsEmptyUtils.stringIsEmpty(new InsertException(RespStatusInfo.DATA_ERROR), couponTypes.getCouponTypeName());
        return couponTypesMapper.insertCouponTypes(couponTypes);
    }

    /**
     * 修改优惠券类型信息
     *
     * @param couponTypes
     * @return
     */
    @Override
    public Integer updateCouponTypes(CouponTypes couponTypes) {
        IsEmptyUtils.integerIsEmpty(new UpdateException(RespStatusInfo.DATA_ERROR), couponTypes.getCouponTypeId());
        IsEmptyUtils.stringIsEmpty(new UpdateException(RespStatusInfo.DATA_ERROR), couponTypes.getCouponTypeName());
        return couponTypesMapper.updateCouponTypes(couponTypes);
    }

    /**
     * 删除优惠券类型信息
     *
     * @param couponTypeId
     * @return
     */
    @Override
    public Integer deleteCouponTypes(Integer couponTypeId) {
        IsEmptyUtils.integerIsEmpty(new SelectException(RespStatusInfo.SELECT_NULL), couponTypeId);
        return couponTypesMapper.deleteCouponTypes(couponTypeId);
    }
}
